package com.lpc.android.abc.base.base;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.lpc.android.abc.base.utils.ActivityStackManager;
import com.lpc.android.abc.base.utils.LogUtil;
import com.lpc.android.abc.base.widget.MProgressDialog;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * Created by lpc on 2016/10/30.
 */

public abstract class BaseActivity extends RxAppCompatActivity {

    //    protected View mContentView;
    protected MProgressDialog mProgressDialog;

    protected Unbinder mUnbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityStackManager.getInstance().push(this);
        setContentView(setActivityLayoutId());
        mUnbinder = ButterKnife.bind(this);
        initData();
    }

    protected abstract int setActivityLayoutId();

    protected abstract void initData();

    public void hideLoadingDialog() {

        LogUtil.i("hideLoadingDialog");
        if (mProgressDialog != null) {
            mProgressDialog.hide();
            mProgressDialog = null;
        }

    }

    public void showLoadingDialog() {

        LogUtil.i("showLoadingDialog");
        mProgressDialog = new MProgressDialog(this, true);
        mProgressDialog.show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        ActivityStackManager.getInstance().pop(this);

        if (mUnbinder != Unbinder.EMPTY) {
            mUnbinder.unbind();
            mUnbinder = null;
        }


    }


}
